#! /usr/bin/python
import itertools
import time

def can_display(die1, die2, nums='01 04 09 16 25 36 49 64 81'.split()):
    """Decide if two dice can display a series of 2-digit numbers.

    >>> can_display(set("056789"), set("123467"))
    True

    """
    for s in (die1, die2):
        if '9' in s: s.add('6')
        elif '6' in s: s.add('9')
    for n in nums:
        d1, d2 = n[0], n[1]
        display = (d1 in die1 and d2 in die2) or (d1 in die2 and d2 in die1)
        if not display:
            return False
    return True

start = time.time()
possible = [str(n) for n in range(10)]
true = set()
for die1 in itertools.combinations(possible, 6):
    for die2 in itertools.combinations(possible, 6):
        if can_display(set(die1), set(die2)):
            true.add(frozenset([frozenset(die1), frozenset(die2)]))
print(len(true), time.time() - start)

print len(true)
if __name__ == "__main__":
    import doctest
    doctest.testmod()


